/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pe.sonrisas.tools.view;

import Complementos.Conexion_BD;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Adxion
 */
public class frmVisualizarPermisos extends javax.swing.JFrame {
    
    int codigo;

    /**
     * Creates new form frmVisualizarPermisos
     */
    public frmVisualizarPermisos() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblVisual = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        tblVisual.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null}
            },
            new String [] {
                "Perfil", "Item", "Ver", "Editar", "Registrar", "Borrar", "Imprimir"
            }
        ));
        tblVisual.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        jScrollPane1.setViewportView(tblVisual);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 614, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 214, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * @param args the command line arguments
     */
    
    
    
    
    public void setCodigo(String xcodigo) {
         Conexion_BD co = new Conexion_BD();
         int fila =0;
         ResultSet rs;
         codigo = Integer.parseInt(xcodigo);
         
         String query = "select pe.nombre, it.nombreOpcion, pr.ver, pr.editar, pr.crear, pr.borrar, pr.imprimir from "+ 
                        " privilegio pr, perfil pe, item it where pr.Perfil_id ='"+codigo +"'  and it.id = pr.Item_id and pr.Perfil_id = pe.id";
        try {
            
            
            co.Conectar();
            rs = co.Consultar(query);
            System.out.println(query);
            while(rs.next()){
                
                 tblVisual.setValueAt( rs.getString(1),fila, 0);
                 tblVisual.setValueAt( rs.getString(2),fila, 1);                 
                 int ver = rs.getInt(3);
                 if(ver == 0)
                 tblVisual.setValueAt( "No",fila, 2);
                 else
                 tblVisual.setValueAt( "Si",fila, 2); 
                 
                 int editar = rs.getInt(4);
                 if(editar == 0)
                 tblVisual.setValueAt( "No",fila, 3);
                 else
                 tblVisual.setValueAt( "Si",fila, 3);   
                 
                 int crear = rs.getInt(5);
                 if(crear == 0)
                 tblVisual.setValueAt( "No",fila, 4);
                 else
                 tblVisual.setValueAt( "Si",fila, 4);   
                 
                 int borrar = rs.getInt(6);
                 if(borrar == 0)
                 tblVisual.setValueAt( "No",fila, 5);
                 else
                 tblVisual.setValueAt( "Si",fila, 5);   
                 
                 int imp = rs.getInt(7);
                 if(imp == 0)
                 tblVisual.setValueAt( "No",fila, 6);
                 else
                 tblVisual.setValueAt( "Si",fila, 6);   
                 
             fila++;       
            }
            
            
            co.Desconectar();
        } catch (Exception ex) {
            Logger.getLogger(frmVisualizarPermisos.class.getName()).log(Level.SEVERE, null, ex);
        } 
        
         
         
    }
    
    public void cargarTabla(){
          
    
    }
    
    
    
    
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(frmVisualizarPermisos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(frmVisualizarPermisos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(frmVisualizarPermisos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(frmVisualizarPermisos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new frmVisualizarPermisos().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable tblVisual;
    // End of variables declaration//GEN-END:variables

    
}
